# -*- coding:utf8 -*- #
# -----------------------------------------------------------------------------------
# ProjectName:  smart-meter-iot-test-console
# FileName:     get_deviceSecret.py
# Author  :     
# Datetime:     2023/3/16 23:56
# Description：
# -----------------------------------------------------------------------------------
import calendar
import time

from common.util.configUtil.configUtil import ConfigUtil
from common.util.logUtil.logUtil import LoggerUtil
from common.util.requestsUtil.requestsUtil import RequestsUtil
from common.util.timeUtil.timeUtil import get_timestamp
from core.mqtt.libProject.getSign.getSign import getSign

req = RequestsUtil()
conf = ConfigUtil()
logger = LoggerUtil()


def getDeviceSecret(deviceName: str) -> dict:
    productKey = conf.get_productkey()
    timestamp = get_timestamp()
    sign = getSign(deviceName, timestamp)
    url = conf.get_mqtt_url(deviceName).format(productKey, deviceName, sign, timestamp)
    try:
        return req.send_request("get", url, params=None), url.split("?")[0]
    except Exception as jsonError:
        logger.error(jsonError)
        return False


if __name__ == '__main__':
    print(getDeviceSecret("455202300106"))
